package orest.back.stat;

import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import orest.back.userneeds.UserNeedsHandler;
import orest.back.userneeds.UserNeedsSql;

import net.ssta.common.Constants;
import net.ssta.common.LoginUser;
import net.ssta.core.base.BaseException;
import net.ssta.core.base.ErrorCode;
import net.ssta.core.base.HandlerBase;
import net.ssta.core.db.DBConnectionProvider;
import net.ssta.core.db.DataBaseExecutor;
import net.ssta.core.db.PagingInfo;
import net.ssta.core.db.Record;
import net.ssta.core.db.RecordSet;
import net.ssta.core.web.RequestKit;
import net.ssta.core.util.DateUtility;
import net.ssta.util.fusionchart.FusionCharts;


/**
 * 
 * @ClassName: IllegalInfoRecordHandler
 * @Description: 信息推荐管理
 * @author:
 * @date:
 * 
 */
public class StatHandler extends HandlerBase
{
    
    
    
    /**
     * 科技成果数量统计
     */
    public RecordSet kjcgSlStat(String startyear , String endyear)
    {
        Connection conn = null;
        RecordSet recordSet = null;
        try
        {
            conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
            DataBaseExecutor m_executor = DataBaseExecutor.getExecutor(conn);
            
            
            String sql = StatSql.kjcgSlStat(startyear,endyear);
            
            recordSet = m_executor.find(sql);
            
            
            return recordSet;
        }
        catch (SQLException e)
        {
            throw new BaseException(ErrorCode.DB_EXCEPTION, e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
                }
            }
        }
    }
    
    
    
    
    
    /**
     * 按课题来源统计
     */
    public RecordSet keTiLaiYuan(String startyear , String endyear)
    {
        Connection conn = null;
        RecordSet recordSet = null;
        try
        {
            conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
            DataBaseExecutor m_executor = DataBaseExecutor.getExecutor(conn);
            
            
            String sql = StatSql.keTiLaiYuan(startyear,endyear);
            
            recordSet = m_executor.find(sql);
            
            return recordSet;
        }
        catch (SQLException e)
        {
            throw new BaseException(ErrorCode.DB_EXCEPTION, e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
                }
            }
        }
    }
    
    
    
    
    /**
     * 按成果水平统计
     */
    public RecordSet ShueiPing(String startyear , String endyear)
    {
        Connection conn = null;
        RecordSet recordSet = null;
        try
        {
            conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
            DataBaseExecutor m_executor = DataBaseExecutor.getExecutor(conn);
            
            
            String sql = StatSql.ShueiPing(startyear,endyear);
            
            recordSet = m_executor.find(sql);
            
            return recordSet;
        }
        catch (SQLException e)
        {
            throw new BaseException(ErrorCode.DB_EXCEPTION, e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
                }
            }
        }
    }
    
    
    
    
    /**
     * 按研究形式统计
     */
    public RecordSet yanjiuXingShi(String startyear , String endyear)
    {
        Connection conn = null;
        RecordSet recordSet = null;
        try
        {
            conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
            DataBaseExecutor m_executor = DataBaseExecutor.getExecutor(conn);
            
            
            String sql = StatSql.yanjiuXingShi(startyear,endyear);
            
            recordSet = m_executor.find(sql);
            
            return recordSet;
        }
        catch (SQLException e)
        {
            throw new BaseException(ErrorCode.DB_EXCEPTION, e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
                }
            }
        }
    }
    
    
    
    
    
    /**
     * 按体现形式统计
     */
    public RecordSet tiXianXingshiShi(String startyear , String endyear)
    {
        Connection conn = null;
        RecordSet recordSet = null;
        try
        {
            conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
            DataBaseExecutor m_executor = DataBaseExecutor.getExecutor(conn);
            
            
            String sql = StatSql.tiXianXingshiShi(startyear,endyear);
            
            recordSet = m_executor.find(sql);
            
            return recordSet;
        }
        catch (SQLException e)
        {
            throw new BaseException(ErrorCode.DB_EXCEPTION, e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
                }
            }
        }
    }
    
    
    
    
    
    /**
     * 按行业分类
     */
    public RecordSet hangYe(String startyear , String endyear)
    {
        Connection conn = null;
        RecordSet recordSet = null;
        try
        {
            conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
            DataBaseExecutor m_executor = DataBaseExecutor.getExecutor(conn);
            
            
            String sql = StatSql.hangYe(startyear,endyear);
            
            recordSet = m_executor.find(sql);
            
            return recordSet;
        }
        catch (SQLException e)
        {
            throw new BaseException(ErrorCode.DB_EXCEPTION, e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
                }
            }
        }
    }
    
    
    
    
    /**
     * 获得行业分类
     */
    public RecordSet getHyTypes()
    {
        Connection conn = null;
        RecordSet recordSet = null;
        try
        {
            conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
            DataBaseExecutor m_executor = DataBaseExecutor.getExecutor(conn);
            
            String sql = StatSql.getHyTypes();
            
            recordSet = m_executor.find(sql);
            
            return recordSet;
        }
        catch (SQLException e)
        {
            throw new BaseException(ErrorCode.DB_EXCEPTION, e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
                }
            }
        }
    }
    
    
    
    /**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FusionCharts cb=new FusionCharts("SDR千时率连续变化情况");
		
		cb.setXAxisName("月份");
		cb.setYAxisName("千时率");
		cb.setChartAttribute("LABELDISPLAY", "Rotate");
		cb.setChartAttribute("SLANTLABELS", "1");
		
		cb.addDataByNoLink("3月份","猪肉",10.5);
		cb.addDataByNoLink("3月份","牛肉",20.5);
		cb.addDataByNoLink("4月份","猪肉",32.5);
		cb.addDataByNoLink("4月份","牛肉",11.5);
		cb.addDataByNoLink("5月份","猪肉",8.5);
		cb.addDataByNoLink("5月份","牛肉",42.5);
		
		
		File xmlFile = new File("d:/text11.xml");
		
		cb.saveDataAsXml("MSColumn3D", xmlFile);
		
	}
    
	
	
	
	
	
	 /**
     * 单位成果数量TOP10
     */
    public RecordSet unitAchieveTop10(String startyear , String endyear,String newenergyclass1)
    {
        Connection conn = null;
        RecordSet recordSet = null;
        try
        {
            conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
            DataBaseExecutor m_executor = DataBaseExecutor.getExecutor(conn);
            
            
            String sql = StatSql.unitAchieveTop10(startyear,endyear,newenergyclass1);
            
            recordSet = m_executor.find(sql);
            
            return recordSet;
        }
        catch (SQLException e)
        {
            throw new BaseException(ErrorCode.DB_EXCEPTION, e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close();
                }
                catch (SQLException e)
                {
                    throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
                }
            }
        }
    }
	
	
	
    
    
    
}
